package hu.uniobuda.nik.bsik2f.googlemapsv2demo;

import android.graphics.Color;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Matusinka Roland
 * Date: 2013.03.25.
 * Time: 13:59
 */

public class MarkerOverlay {

    GoogleMap map;
    List<Marker> markerList;
    Polyline line;

    public MarkerOverlay(GoogleMap map) {
        this.map = map;
        this.markerList = new ArrayList<Marker>();
        this.line = map.addPolyline(new PolylineOptions()
                .color(Color.BLUE)
                .width(25));
    }

    public Marker addMarker(LatLng position, String title) {
        Marker marker = map.addMarker(new MarkerOptions()
                .position(position)
                .title(title)
                .draggable(false));
        markerList.add(marker);

        List<LatLng> linePoints = line.getPoints();
        linePoints.add(position);
        line.setPoints(linePoints);

        return marker;
    }

    public void removeAll() {
        for (Marker m : markerList) m.remove();
        markerList.clear();
    }
}
